/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProductView.java
 *
 * Created on 2011-feb-22, 15:54:31
 */

package imat;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import se.chalmers.ait.dat215.project.ShoppingItem;

/**
 *
 * @author Andreas
 */
public class ShoppingItemView extends JPanel {

    private ShoppingItemPresenter shoppingItemPresenter;
    private SideTrolleyPresenter sideTrolleyPresenter;

    /** Creates new form ProductView */
    public ShoppingItemView(SideTrolleyPresenter presenter) {
        initComponents();

        shoppingItemPresenter = new ShoppingItemPresenter(this);
        sideTrolleyPresenter = presenter;
    }

    public void setShoppingItem(ShoppingItem item) {
        shoppingItemPresenter.setShoppingItem(item);
    }

    public JLabel getProductNameLabel () {
        return productName;
    }

    public JSpinner getAmountSpinner () {
        return amount;
    }

    public JLabel getProductPriceLabel() {
        return productPrice;
    }

    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        removeButton = new javax.swing.JButton();
        amount = new javax.swing.JSpinner();
        jPanel1 = new javax.swing.JPanel();
        productName = new javax.swing.JLabel();
        productPrice = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(imat.IMatApp.class).getContext().getResourceMap(ShoppingItemView.class);
        removeButton.setIcon(resourceMap.getIcon("removeButton.icon")); // NOI18N
        removeButton.setText(resourceMap.getString("removeButton.text")); // NOI18N
        removeButton.setName("removeButton"); // NOI18N
        removeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonPressed(evt);
            }
        });

        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(180, 30));

        amount.setModel(new javax.swing.SpinnerNumberModel(Double.valueOf(0.0d), null, null, Double.valueOf(1.0d)));
        amount.setToolTipText(resourceMap.getString("amount.toolTipText")); // NOI18N
        amount.setName("amount"); // NOI18N
        amount.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                amountStateChanged(evt);
            }
        });

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setOpaque(false);
        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));

        productName.setFont(resourceMap.getFont("productName.font")); // NOI18N
        productName.setText(resourceMap.getString("productName.text")); // NOI18N
        productName.setToolTipText(resourceMap.getString("productName.toolTipText")); // NOI18N
        productName.setName("productName"); // NOI18N
        jPanel1.add(productName);

        productPrice.setFont(resourceMap.getFont("productPrice.font")); // NOI18N
        productPrice.setText(resourceMap.getString("productPrice.text")); // NOI18N
        productPrice.setName("productPrice"); // NOI18N
        jPanel1.add(productPrice);

        jLabel1.setIcon(resourceMap.getIcon("jLabel1.icon")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setToolTipText(resourceMap.getString("jLabel1.toolTipText")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(amount, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(amount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addContainerGap(70, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void deleteButtonPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonPressed
        shoppingItemPresenter.removeItem();
    }//GEN-LAST:event_deleteButtonPressed

    private void amountStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_amountStateChanged
        shoppingItemPresenter.valueChanged((Double)amount.getValue());
        sideTrolleyPresenter.updateTotalPrice();
    }//GEN-LAST:event_amountStateChanged

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
          shoppingItemPresenter.removeItem();
    }//GEN-LAST:event_jLabel1MouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSpinner amount;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel productName;
    private javax.swing.JLabel productPrice;
    private javax.swing.JButton removeButton;
    // End of variables declaration//GEN-END:variables

}
